package compare;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.locks.ReentrantLock;

class LockTest extends TestTemplate{
    ReentrantLock lock=new ReentrantLock();
    public LockTest(String id, int round, int threadNum, CyclicBarrier cb){
        super( id, round, threadNum, cb);
    }
    /**
     * synchronized关键字不在方法签名里面，所以不涉及重载问题
     */
//  @Override
//  @Override
    long getValue() {
        try{
            lock.lock();
            return super.countValue;
        }finally{
            lock.unlock();
        }
    }
//  @Override
    void sumValue() {
        try{
            lock.lock();
            super.countValue+=preInit[index++%round];
        }finally{
            lock.unlock();
        }
    }
}
 